package com.study.spring.kafka;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 * @date 2022年05月03日 12:49
 * @description
 */
@RestController
@ConditionalOnBean(KafkaAutoConfiguration.class)
public class Producer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    @GetMapping("send")
    public void send(){

        String message = "你好，我是Java旅途";
        // 第一个参数 topic
        // 第二个参数 消息
        kafkaTemplate.send("first-topic",message);
    }
}
